#include <REGX52.H>
#include <INTRINS.H>
#include "Delay.h"

// 0-9 A-F对应的段选
unsigned char NixieTable[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, 0x40, 0x00};
unsigned char NixieWithDotTable[] = {0x3f | 0x80,0x06 | 0x80,0x5b | 0x80,0x4f | 0x80,0x66 | 0x80,0x6d | 0x80,0x7d | 0x80,0x07 | 0x80,0x7f | 0x80,0x6f | 0x80};


/**
  * @brief   位选
  * @details 
  * @param   loc 范围1-8
  * @retval  
  */
void ChoiceLocation(unsigned char loc) {
	loc = ~(loc - 1);
	P2_4 = (loc & 4) >> 2;
	P2_3 = (loc & 2) >> 1;
	P2_2 = loc & 1;
}

/**
  * @brief   在指定位置显示数字
  * @details 
  * @param   loc 显示的位置1-8
  * @param   number 显示的数字 0-9
  * @retval  
  */
void NixieNoReset(unsigned char loc, unsigned char number) {
	ChoiceLocation(loc);

	P0 = NixieTable[number];
	Delay(1);
}

/**
  * @brief   在指定位置显示数字
  * @details 显示后会重置，消除残影
  * @param   loc 显示的位置1-8
  * @param   number 显示的数字 0-9
  * @retval  
  */
void Nixie(unsigned char loc, unsigned char number) {
	NixieNoReset(loc, number);
	P0 = 0x00;
}

/**
  * @brief   在指定位置显示数字并跟随小数点
  * @details 显示后会重置，消除残影
  * @param   loc 显示的位置1-8
  * @param   number 显示的数字 0-9
  * @retval  
  */
void NixieWithDot(unsigned char loc, unsigned char number) {
	ChoiceLocation(loc);

	P0 = NixieWithDotTable[number];
	Delay(1);
	P0 = 0x00;
}

